package com.mall.common.dao.impl;

import java.util.List;
import java.util.Set;

import org.springframework.stereotype.Repository;

import com.mall.common.dao.MenuDao;
import com.mall.common.domain.manage.Menu;
import com.mall.common.hibernate.Finder;

/**
 * Dao实现类 - 资源
 */
@Repository
public class MenuDaoImpl extends BaseDaoImpl<Menu, Long> implements MenuDao {

	@Override
	public List<Menu> getAllMenus(){
		String hql = "from Menu bean";
		Finder f = Finder.create(hql);
		List<Menu> menus = f.findHQLList();
		return menus;
	}
	
	public List<Menu> getTopList(boolean displayOnly){
		Finder f = getTopFinder(displayOnly);
		return f.findHQLList();
	}
	
	@Override
	@SuppressWarnings({ "rawtypes" })
	public List<Menu> getTopListByRigth(Set roles) {
		Finder f = Finder.create("select bean from Menu bean");
		f.append(" join bean.roleSet role");
		f.append(" where roleSet in (:roles)");
		f.setParamList("roles", roles);
		f.append(" and bean.parent.id is null");
		f.append(" order by bean.priority asc,bean.id asc");
		return f.findHQLList();
	}
			
	private Finder getTopFinder(boolean displayOnly) {
		Finder f = Finder.create("from Menu bean");
		f.append(" where bean.upDomain.id is null");
		return f;
	}
}